<template>
  <div>
    <el-card shadow="never">
      <div slot="header">
        <el-button @click="handleBack">返回</el-button>
      </div>
      <start-tabs ref="startTabs" />
    </el-card>
  </div>
</template>

<script>
import StartTabs from './StartTabs'
import { getSession, setSession, removeSession } from '@/utils/util'
import { startInternal, internalDetailParam, taskListGet } from '@/api/satisfaction'

export default {
  components: {
    StartTabs
  },
  data() {
    return {
      row: this.$route.params.row || getSession('satisListRow')
    }
  },
  created() {
    this.getData()
  },
  methods: {
    handleBack() {
      removeSession('satisListRow')
      this.$router.push({ name: 'satisfactionTask' })
    },
    async getData() {
      console.log('row', this.row)

      if (this.row) {
        console.log('刚进页面')
        // this.init()

        setSession('satisListRow', this.row)
        const res = await taskListGet({ internalTaskId: this.row.internalTaskId })
        console.log('res', res)
        if (res && res.data.length > 0) {
          let arr = []
          let all = []
          res.data.map(v => {
            if (v.internalNoteVOList) {
              all = [...all, ...v.internalNoteVOList]
            } else {
              all = [...all]
            }
          })
          console.log('all', all)
          this.$refs.startTabs.getData(res.data)
          this.listData = res.data
          console.log('listData', this.listData)
        }
      } else {
        // this.$message.error('页面发生错误，即将跳转回列表页')
        // setTimeout(() => {
        //   this.$router.push({
        //     name: 'satisfactionEvaluateTable'
        //   })
        // }, 1000)
      }
    },
    async init() {
      console.log('init===============')

      let res = ''
      const { evalTaskId, planTargetId, evalPlanId } = this.row
      if (this.type === 'evaluate') {
        // 开始考评调用
        res = await startInternal({ internalPlanId: this.row.internalPlanId })
      } else {
        // 详情调用
        console.log('详情 row', this.row)
        const { internalTaskId, targetId } = this.row
        res = await internalDetailParam({ internalTaskId, targetId })
      }
      let all = []
      if (this.type !== 'detail') {
        res.data.map(v => {
          all = [...all, ...v.internalPlanItemList]
        })
      } else {
        res.data.map(v => {
          all = [...all, ...v.internalNoteVOList]
        })
      }
      console.log('res.data', res.data)
      this.$refs.startTabs.getData(res.data)
    }
  }
}
</script>
